// Package coding_round_1 4_429
// @Title coding_round_1
// @Description  429. N 叉树的层序遍历
// @Author  == 琳琳也叫王木木 ==  2021/9/3 20:58
// @Create  2021/9/3 20:58
package coding_round_1

func levelOrder(root *Node) [][]int {
	if root == nil {
		return nil
	}
	ans := [][]int{}
	queue := []*Node{root}
	for len(queue) > 0 {
		size := len(queue)
		tArr := []int{}
		for i := 0; i < size; i++ {
			node := queue[0]
			queue = queue[1:]
			tArr = append(tArr, node.Val)
			for j := 0; j < len(node.Children); j++ {
				queue = append(queue, node.Children[j])
			}
		}
		ans = append(ans, tArr)
	}
	return ans
}
